package com.wn.purchaeReturn.controller;

import com.wn.purchaeReturn.entity.PurPurchasebilldetail;
import com.wn.purchaeReturn.poitool.MyExcelExportUtil;
import com.wn.purchaeReturn.service.PurPurchasebilldetailService;
import com.woniu.common.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author: yyc
 * @Date: 2022-04-18-14:40
 * @Description:
 */
@RestController
@RequestMapping("/Purchasebilldetail")
public class PurPurchasebilldetailController {
    @Autowired
    private PurPurchasebilldetailService purPurchasebilldetailService;

    /**
     * 查询订单号为purchaseno的所有的商品信息
     * @param purchaseno
     * @return
     */
    @GetMapping("/{id}")
    public Result selectBypurchaseno(@PathVariable("id") String purchaseno){
        return Result.ok().data("list",purPurchasebilldetailService.selectBypurchaseno(purchaseno));
    }

    /**
     *
     * @param response
     */
    @RequestMapping("/exportPurPurchasebill")
    public void exportPurPurchasebill(HttpServletResponse response) {
        try {
            List<PurPurchasebilldetail> purPurchasebilldetails = purPurchasebilldetailService.selectAll();
            MyExcelExportUtil.exportExcel(purPurchasebilldetails, PurPurchasebilldetail.class,"采购单","采购单详情",response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
